
#ifndef SX_QGL_VIEWPORT_H
#define SX_QGL_VIEWPORT_H

#include <QGLWidget>
#include <sxQGL_ViewportListener.h>
#include <sxArrayList.h>

namespace Sx {
namespace QtInterface {

/* 
 * This class is required because of the existence of the QGLWidget and the
 * requirement of the QViewport abstract class. Because Qt cannot handle the
 * multiple inheritance of Q_OBJECTS, this class provides the implementation
 * of the QGLWidget class that can be used within a QOpenGL_Viewport class
 * that extends QViewport. This means that the QOpenGL_Viewport class can
 * inherit from QViewport and also provide the functionality of a QGLWidget.
 * This does introduce an extra level of indirection (due to the composition)
 * however there is no other solution.
 * 
 * TLDR: This class passes the QGLWidget init, paint, and resize events to
 * the provided set of QGL_ViewportListeners.
 */
class QGL_Viewport : public QGLWidget {
	Q_OBJECT

public:
	QGL_Viewport(QWidget* parent = nullptr, Qt::WFlags flags = 0);
	QGL_Viewport(QWidget* parent, QGL_Viewport* share, Qt::WFlags flags = 0);
	virtual ~QGL_Viewport();

	bool addViewportListener(QGL_ViewportListener* listener);
	bool removeViewportListener(QGL_ViewportListener* listener);

protected:
	void initializeGL();
	void paintGL();
	void resizeGL(int width, int height);

	/* POINTER_OWNERSHIP: NO (Handled by Qt) */
	Util::ArrayList<QGL_ViewportListener*> viewportListeners;
};

}

}

#endif
